package com.qiguliuxing.dts.service.seckill.constant;

import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.Objects;

/**
 * @author liumeng
 */
public class MerchantEmailConstant {

    public final static String SUCCESS_EMAIL_TEMPLATE = "<div>" +
            "<font color='#CCCC00' size='5' weight='bold'>#{mallName}特此</font>" +
            "</div>" +
            "<div>" +
            "<font color='#CC0033'>恭喜您！您申请的店铺#{shopName}入驻审核已经通过！</font>" +
            "</div>" +
            "<div>" +
            "<font color='#339900'>现在您可以登录商户端了，链接为：<a href='#{merchantLink}'>#{merchantLink}</a></font>" +
            "</div>" +
            "<div>" +
            "<font color='#CC9900'>祝您生意兴隆，生活愉快。</a></font>" +
            "</div>";

    public final static String FAIL_EMAIL_TEMPLATE = "<div>" +
            "<font color='#CCCC00' size='5'>#{mallName}特此</font>" +
            "</div>" +
            "<div>" +
            "<font color='#CC0033'>遗憾的通知您！您申请的店铺#{shopName}入驻审核未通过！</font>" +
            "</div>" +
            "<div>" +
            "<font color='#CC9900'>原因是#{approveOpinion}</a></font>" +
            "</div>" +
            "<div>" +
            "<font color='#339900'>您可以再次访问商户端链接<a href='#{merchantLink}'>#{merchantLink}</a>，重新申请入驻，祝您好运。</font>" +
            "</div>";

    public static String appendCoat(String attr){
        return "#\\{"+attr+"}";
    }

    public static String getEmailContent(Map<String,Object> params,String template){
        final String[] content = {template};
        if(Objects.isNull(params)){return StringUtils.EMPTY;}
        params.keySet().forEach( key->
            content[0] = content[0].replaceAll(appendCoat(key),String.valueOf(params.get(key)))
        );
        return content[0];
    }
}
